//
//  JSLSettingCell.m
//  JingleSpeedLoan
//
//  Created by 宋志彬 on 2018/7/29.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "JSLSettingCell.h"

@interface JSLSettingCell()
@property (nonatomic,weak) UILabel *titleView;

@property (nonatomic,weak) UIImageView *arrowImage;

@property (nonatomic,weak) UILabel *subTitleView;
@end

@implementation JSLSettingCell

#pragma mark - init
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
      
        
        [self setUpAllChildView];
        
    }
    return self;
}

- (void)configSettingViewData:(NSDictionary *)info {

    self.titleView.text = info[@"title"];
    
    if ([JSLKitFactory isNotNull:info[@"sutitle"]] ) {
        self.subTitleView.text= info[@"sutitle"];
        self.arrowImage.hidden = YES;
    }else {
        self.subTitleView.text = @"";
        self.arrowImage.hidden = NO;
    }
}

- (void)setUpAllChildView {
    self.titleView  = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:nil font:LIGHT_FONT(14) textColor:[@"#999999" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.contentView];
    
    self.arrowImage = [JSLKitFactory jsl_imageViewWithFrame:CGRectZero imageName:@"detial-arrow" superView:self.contentView];
//    self.arrowImage.backgroundColor = [UIColor redColor];
    
    self.subTitleView = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:nil font:LIGHT_FONT(14) textColor:[@"#666666" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.contentView];
    
}

#pragma mark - 配置视图
- (void)layoutSubviews{
    [super layoutSubviews];
   
    CGSize titleSize = [self.titleView.text sizeWithAttributes:@{NSFontAttributeName : self.titleView.font}];
    self.titleView.frame = CGRectMake(20*AutoSizeScaleXX, CGRectGetHeight(self.contentView.frame)*0.5-titleSize.height*0.5, titleSize.width, titleSize.height);
    
    self.arrowImage.frame = CGRectMake(SCREEN_WIDTH - 20*AutoSizeScaleXX - 10*AutoSizeScaleXX,  CGRectGetHeight(self.contentView.frame)*0.5 - 10*AutoSizeScaleYY*0.5, 10*AutoSizeScaleXX, 10*AutoSizeScaleYY);
    
    CGSize subTitleSize = [self.subTitleView.text sizeWithAttributes:@{NSFontAttributeName : self.subTitleView.font}];
    self.subTitleView.frame = CGRectMake(SCREEN_WIDTH-subTitleSize.width -20*AutoSizeScaleXX, CGRectGetHeight(self.contentView.frame)*0.5-subTitleSize.height*0.5, subTitleSize.width, subTitleSize.height);
}

#pragma mark - 创建cell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * ID = @"JSLSettingCell";
    id cell = [tableView dequeueReusableCellWithIdentifier:ID ];
    
    if (cell == nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    return cell;
}

@end
